package com.caojing.syby.ui.cart;


import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.caojing.syby.R;
import com.caojing.syby.base.BaseFragment;
import com.caojing.syby.ui.cart.cartsharefragment.CartShareFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class CartFragment extends BaseFragment {

    @Bind(R.id.tablayout_cartfragment)
    TabLayout tablayoutCartfragment;
    @Bind(R.id.viewpager_cartfragment)
    ViewPager viewpagerCartfragment;

    private String []tabNames;
   //用于区分每个fragment的不同之处
    private int [] bcs={0,1,2,3,4,5,6,7,8,9,10};
    private List<CartShareFragment>cartShareFragmentList=new ArrayList<>();



    @Override
    protected int getLayoutId() {
        return R.layout.fragment_cart;
    }

    @Override
    protected void initView(View view) {

        //设置指示器的颜色
        tablayoutCartfragment.setSelectedTabIndicatorColor(Color.RED);
        //设置tab的文本颜色
        tablayoutCartfragment.setTabTextColors(Color.BLACK,Color.RED);

        //设置mode 滚动模式动态改变tabLayout宽度
//        tablayoutTenbuy.setTabMode(TabLayout.MODE_SCROLLABLE);
        tablayoutCartfragment.setTabMode(TabLayout.MODE_SCROLLABLE);

        tablayoutCartfragment.getTabGravity();

//        得到tablayout的每个tab的值
        tabNames=getResources().getStringArray(R.array.carTabNames);

        for (int i=0;i<tabNames.length;i++){
            CartShareFragment cartShareFragment= CartShareFragment.newInstance(bcs[i]+"");
            cartShareFragmentList.add(cartShareFragment);

        }


//        这里是公用tenbuyfragment中的viewpageradapter
       CarfragmentViewpagerAdapter adapter=new CarfragmentViewpagerAdapter(getChildFragmentManager(),cartShareFragmentList,tabNames);
        viewpagerCartfragment.setAdapter(adapter);
       //将tablayout和viewpager进行关联
        tablayoutCartfragment.setupWithViewPager(viewpagerCartfragment);
    }

    @Override
    protected void initData() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
